package com.sui.bigdata.flink.sql.submitTask;

import com.feidee.fdcommon.model.StringResponse;
import com.feidee.fdcommon.util.HttpUtil;
import org.apache.http.Consts;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.junit.Test;

/**
 * @author YongChen
 * @date 2020/3/9 15:42
 * @description
 * @email yong_chen@sui.com
 */
public class restart {

    @Test
    public void test1() throws  Exception{
        String url = "http://10.201.7.131:18001/rtc-admin/job?action=restart";

        String sql =  " "+
                " CREATE TABLE MyTable(\n" +
                "    suid varchar,\n" +
                "    click int\n" +
                " )WITH(\n" +
                "    type ='kafka',\n" +
                "    bootstrapServers ='10.201.7.115:9092,10.201.7.120:9092,10.201.7.121:9092',\n" +
                "    offsetReset ='latest',\n" +
                "    topic ='flinkwindow_test',\n" +
                "    parallelism ='1'\n" +
                " );\n" +


                "select  \n" +
                "   suid,\n" +
                "   click \n" +
                "from \n" +
                "   MyTable; \n";


//        String data = "{\"jobName\":\"risk_app_algorithm_score\",\"parallelism\":\"1\",\"taskManagerMemory\":\"1024\"}";

        String data = "{\"jobName\":\"kudu_test\",\"extendParam\":{\"sql.checkpoint.interval\":\"30000\"},\"savepoint\":\"true\"}";



//        String data = "{\"execSql\":\"" + sql +
//                "\",\"jobName\":\"flink_select_test\"," +
//                "\"developer\":\"yong_chen\"," +
//                "\"alarmGroupPhone\":\"\"," +
//                "\"parallelism\":\"1\"," +
//                "\"queue\":\"root.data_team\"," +
//                "\"jobManagerMemory\":\"1024\"," +
//                "\"taskManagerMemory\":\"1024\"," +
//                "\"extendParam\":{\"time.characteristic\":\"EventTime\"}," +
//                "\"slots\":\"1\"," +
//                "\"savepoint\":\"true\"}";

        System.out.println(data);
        StringEntity stringEntity = new StringEntity(data, Consts.UTF_8);
        stringEntity.setContentEncoding("UTF-8");
        stringEntity.setContentType("application/json");

        HttpPost httpPost=new HttpPost(url);

        RequestConfig requestConfig = RequestConfig.custom().setConnectTimeout(500000).build();
        httpPost.setEntity(stringEntity);
        httpPost.setConfig(requestConfig);
        StringResponse response = HttpUtil.post(httpPost);
        System.out.println(">>>>> "+response.getResponseBody());
    }
}
